package com.esm.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * 分页工具
 * @author 王文成
 *
 */
public class PagingUtil 
{
	/**
	 * 
	 * @param scount  总数
	 * @param currentPage  当前页
	 * @param pageSize  分页条数
	 * @return
	 */
	 public static  String  getPageList(int scount,int currentPage,int pageSize,String servlet,HttpServletRequest request)
	 {
	 	//求页码数
    	int totalPage = (scount%pageSize == 0)?(scount/pageSize):(scount/pageSize+1);
    	StringBuffer str = new StringBuffer();
    	str.append("<li><a href='javascript:void(0);' onclick=\"pageInit(1);\">首页</a></li>");
    	if(currentPage == 1)
    	{
    		str.append("<li class='disabled'><a href='javascript:void(0);'>上一页</a></li>");
    	}
    	else
    	{
    		str.append("<li ><a onclick=\"pageInit("+(currentPage-1)+");\" href='javascript:void(0);'>上一页</a></li>");
    	}
    	for (int i = currentPage-3; i <= currentPage+3; i++) 
    	{
			if(i < 1 || i > totalPage)
			{
				continue;
			}
			if(i == currentPage)
			{
				str.append("<li class='active'><a href='javascript:void(0);'>"+i+"</a></li>");
			}
			else
			{
				str.append("<li ><a href='javascript:void(0);' onclick=\"pageInit("+i+");\">"+i+"</a></li>");
			}
		}
    	if(currentPage == totalPage)
    	{
    		str.append("<li class='disabled'><a href='javascript:void(0);'>下一页</a></li>");
    	}
    	else
    	{
    		str.append("<li ><a href='javascript:void(0);' onclick=\"pageInit("+(currentPage+1)+");\">下一页</a></li>");
    	}
    	str.append("<li><a href='javascript:void(0);' onclick=\"pageInit("+totalPage+");\">尾页</a></li>");
    	return str.toString();
    }	
	 /**
	  * 
	  * @param ucount  总数
	  * @param currentPage  当前页
	  * @param pageSize  分页条数
	  * @return
	  */
	 public static  String  getSelDepEmpPageList(int ucount,int currentPage,int pageSize)
	 {
		 //求页码数
		 int totalPage = (ucount%pageSize == 0)?(ucount/pageSize):(ucount/pageSize+1);
		 StringBuffer str = new StringBuffer();
		 str.append("<li><a href='getDeptEmp?page=1'>首页</a></li>");
		 if(currentPage == 1)
		 {
			 str.append("<li class='disabled'><a href='#'>上一页</a></li>");
		 }
		 else
		 {
			 str.append("<li ><a href='getDeptEmp?page="+(currentPage-1)+"'>上一页</a></li>");
		 }
		 for (int i = currentPage-3; i <= currentPage+3; i++) 
		 {
			 if(i < 1 || i > totalPage)
			 {
				 continue;
			 }
			 if(i == currentPage)
			 {
				 str.append("<li class='active'><a href='#'>"+i+"</a></li>");
			 }
			 else
			 {
				 str.append("<li ><a href='getDeptEmp?page="+i+"'>"+i+"</a></li>");
			 }
		 }
		 if(currentPage == totalPage)
		 {
			 str.append("<li class='disabled'><a href='#'>下一页</a></li>");
		 }
		 else
		 {
			 str.append("<li ><a href='getDeptEmp'?page="+(currentPage+1)+"'>下一页</a></li>");
		 }
		 str.append("<li><a href='getDeptEmp?page="+totalPage+"'>尾页</a></li>");
		 return str.toString();
	 }	
	 /**
	 *
	 * @param scount  总数
	 * @param currentPage  当前页
	 * @param pageSize  分页条数
	 * @return
	 */
	 public static  String  getPagingList(int ucount,int currentPage,int pageSize)
	 {
	 	//求页码数
    	int totalPage = (ucount%pageSize == 0)?(ucount/pageSize):(ucount/pageSize+1);
    	StringBuffer str = new StringBuffer();
    	str.append("<li><a href='departmentSearch?page=1'>首页</a></li>");
    	if(currentPage == 1)
    	{
    		str.append("<li class='disabled'><a href='#'>上一页</a></li>");
    	}
    	else
    	{
    		str.append("<li ><a href='departmentSearch?page="+(currentPage-1)+"'>上一页</a></li>");
    	}
    	for (int i = currentPage-3; i <= currentPage+3; i++) 
    	{
			if(i < 1 || i > totalPage)
			{
				continue;
			}
			if(i == currentPage)
			{
				str.append("<li class='active'><a href='#'>"+i+"</a></li>");
			}
			else
			{
				str.append("<li ><a href='departmentSearch?page="+i+"'>"+i+"</a></li>");
			}
		}
    	if(currentPage == totalPage)
    	{
    		str.append("<li class='disabled'><a href='#'>下一页</a></li>");
    	}
    	else
    	{
    		str.append("<li ><a href='departmentSearch'?page="+(currentPage+1)+"'>下一页</a></li>");
    	}
    	str.append("<li><a href='departmentSearch?page="+totalPage+"'>尾页</a></li>");
    	return str.toString();
    }	
}
